home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / MEMMON_F / MMRT.C < prev    next >
Text File  |  1990-03-02  |  8KB  |  267 lines

  1. /*
  2.  * mmrt.c: graphics driver for Raster Tech One/80.
  3.  *
  4.  *  This Raster Tech unit is a 1280 x 1024 x 24 color display, where
  5.  *  the 8 bits of each color plane are interpreted through a lookup table.  
  6.  *  We use it as if it were 1280 x 1024 x 8 display, with lookup.
  7.  */
  8.  
  9. #include <varargs.h>
  10. #include "memmon.h"
  11.  
  12. hidden novalue rtcmd Params((/*varargs*/));
  13.  
  14. #define HSize 1280            /* horizontal screen size */
  15. #define VSize 1024            /* vertical screen size */
  16.  
  17. #define CTAddr 0xFC00            /* color table address in raster tech */
  18.  
  19. /* raster tech command bytes and formats */
  20. #define SGPX    "\004"            /* enter graphics (standard) */
  21. #define EGPX    "\005"            /* enter graphics (redef from \004) */
  22. #define BLINKC    "\043"
  23. #define BLINKE    "\040bbbb"
  24. #define BLINKR    "\042b"
  25. #define CLEAR    "\207"
  26. #define CONFIG    "\044wwwwwwww"
  27. #define DRW3R    "\203bb"
  28. #define LUT8    "\034bbbb"
  29. #define MOVABS    "\001xy"
  30. #define PIXFUN    "\073b"
  31. #define POKE    "\276ww"
  32. #define PRMFIL    "\037b"
  33. #define QUIT    "\377"
  34. #define RECREL    "\211xy"
  35. #define RGBTRU    "\116b"
  36. #define SCRORG    "\066xy"
  37. #define SPCHAR    "\262bbb"
  38. #define TEXTN    "\251bbww"
  39. #define TEXT1    "\220b"
  40. #define VAL8    "\206b"
  41. #define VECPAT    "\056w"
  42. #define WINDOW    "\072xyxy"
  43. #define WMSK16    "\104w"
  44. #define ZOOM    "\064b"
  45.  
  46. static int xll, yll;            /* screen coordinates of LL corner */
  47.  
  48. /*
  49.  * devsetup() - set globals to device-dependent values.
  50.  */
  51. novalue devsetup()
  52.    {
  53.    granularity = 2;
  54.    width = HSize;
  55.    height = VSize;
  56.    textrow = 20;
  57.    textsep = 6;
  58.    memrow = 20;
  59.    }
  60.  
  61. /*
  62.  * devinit() - initialize for graphics output.
  63.  */
  64. novalue devinit()
  65.    {
  66.    static char obuf[BUFSIZ];        /* small buffer for smoother output */
  67.    int xsize, ysize;
  68.  
  69.    if (height > VSize)            /* limit height to maximum */
  70.       height = VSize;
  71.    if (width > HSize)            /* similarly for width */
  72.       width = HSize;
  73.  
  74.    xll = - width / 2;            /* center horizontally */
  75.    yll = (VSize / 2) - height;        /* move to top of screen */
  76.  
  77.    litout();                /* set literal output mode if tty line*/
  78.    setbuf(stdout, obuf);        /* use small buffer -- less jerky */
  79.  
  80.    putchar(0);                /* try to flush incomplete commands */
  81.    putchar(0);
  82.    putchar(0);
  83.    putchar(0);
  84.    rtcmd(QUIT);                /* exit graphics mode */
  85.  
  86.    rtcmd(SGPX);                /* enter gpx mode, if not yet redef */
  87.    rtcmd(SPCHAR, 0, 1, *EGPX);        /* redefine from \04 to \05 */
  88.    rtcmd(QUIT);                /* exit graphics mode */
  89.  
  90.    rtcmd(EGPX);                /* enter graphics mode (for sure) */
  91.    rtcmd(CONFIG, 0x2000, 0x400, 0x800, 0x1000, 0x400, 0, 0, 0);
  92.                     /* configure memory */
  93.    rtcmd(RGBTRU, 1);            /* use 24-bit mode */
  94.    rtcmd(ZOOM, 1);            /* reset zoom */
  95.    rtcmd(SCRORG, 0, 0);            /* set screen origin */
  96.    rtcmd(WINDOW, -HSize / 2, -VSize / 2, HSize / 2 - 1, VSize / 2 - 1);
  97.                     /* set clipping window */
  98.    rtcmd(PRMFIL, 1);            /* set filled primitives */
  99.    rtcmd(VECPAT, 0xFFFF);        /* set solid lines */
  100.    rtcmd(PIXFUN, 0);            /* set opaque mode */
  101.    rtcmd(WMSK16, 0xFFFF);        /* enable all bit planes */
  102.  
  103.    /* set text paramaters. constants were empirically determined. */
  104.    xsize = 2.6 * width / TextLength;
  105.    ysize = 1.6 * textrow;
  106.    rtcmd(TEXTN, xsize, ysize, 0, 0);    /* set text parameters */
  107.  
  108.    rtcmd(BLINKC);            /* clear blink table */
  109.    rtcmd(BLINKR, 20);            /* set blink rate (1.5 Hz) */
  110.    rtcmd(BLINKE, 7, Unmarked + C_Blink, 0, 255);  /* blink black/white */
  111.    }
  112.  
  113. /*
  114.  * devmap() - load color map into device.  Also write a shadow copy of the map
  115.  *  in high Raster Tech memory for use by rtscreen(1).
  116.  */
  117. novalue devmap()
  118.    {
  119.    int i;
  120.  
  121.    for (i = 0; i < MapSize; i++) 
  122.       rtcmd(LUT8, i, cmap[i].red, cmap[i].green, cmap[i].blue);
  123.    for (i = 0; i < MapSize; i += 2)  {    
  124.       rtcmd(POKE, CTAddr + i, (cmap[i].red << 8) | cmap[i+1].red);
  125.       rtcmd(POKE, CTAddr + i + 256, (cmap[i].green << 8) | cmap[i+1].green);
  126.       rtcmd(POKE, CTAddr + i + 512, (cmap[i].blue << 8) | cmap[i+1].blue);
  127.       }
  128.    }
  129.  
  130. /*
  131.  * devflood(c) - fill screen with color c.
  132.  */
  133. novalue devflood(c)
  134. int c;
  135.    {
  136.    rtcmd(VAL8, c);            /* set color for clear */
  137.    rtcmd(CLEAR);            /* clear screen */
  138.    }
  139.  
  140. /*
  141.  * devpaint(start, n, color, b) - paint n pixels in given color.
  142.  *  If b >= 0, the last pixel is to be that color instead (for a border)
  143.  */
  144. novalue devpaint(s, n, c, b)
  145. word s, n;
  146. int c, b;
  147.    {
  148.    int x, y;
  149.  
  150.    if (b >= 0)                /* if border, decr total count*/
  151.       n--;
  152.    x = s % width;            /* where on row,  which row? */
  153.    y = memheight - memrow * (1 + s / width);
  154.    rtcmd(VAL8, c);            /* set color */
  155.    while (x + n >= width)  {        /* draw all rows but last */
  156.       rtcmd(MOVABS, xll + x, yll + y);        /* position to LL corner */
  157.       rtcmd(RECREL, width - 1 - x, memrow - 1 - 1);  /* draw to UR corner */
  158.       n -= width - x;                /* decr count */
  159.       x = 0;                    /* move to start of next row */
  160.       y -= memrow;
  161.       }
  162.    if (n) {                /* last row */
  163.       rtcmd(MOVABS, xll + x, yll + y);        /* position */
  164.       rtcmd(RECREL, n - 1, memrow - 1 - 1);    /* draw */
  165.       x += n;
  166.       }
  167.    if (b >= 0)  {            /* border */
  168.       rtcmd(VAL8, b);                /* color */
  169.       rtcmd(MOVABS, xll + x, yll + y);        /* position */
  170.       rtcmd(DRW3R, 0, memrow - 1 - 1);        /* draw */
  171.       }
  172.    }
  173.  
  174. /*
  175.  * devtext(string, row, col, fgcolr, bgcolr) - output text.
  176.  */
  177. novalue devtext(s, row, col, fg, bg)
  178. char *s;
  179. int row, col, fg, bg;
  180.    {
  181.    int x, y, n;
  182.    float charwidth;
  183.  
  184.    charwidth = (float)width / (float)TextLength;
  185.    n = strlen(s);
  186.    x = col * charwidth;                /* where on line? */
  187.    y = height - textrow * (row + 1) + 1;    /* which line? */
  188.    rtcmd(VAL8, bg);                /* set bkground color */
  189.    rtcmd(MOVABS, xll + x, yll + y);        /* position */
  190.    rtcmd(RECREL, (int)(charwidth * (n + 1)) - 2, textrow - 2);
  191.                         /* draw background */
  192.    if (fg == bg || n == 0)            /* if no text */
  193.       return;
  194.    rtcmd(VAL8, fg);                /* set text color */
  195.    rtcmd(MOVABS, xll + x + (int)(.45*charwidth), yll + y + (int)(.25*textrow));
  196.    rtcmd(TEXT1, n);                /* issue text func */
  197.    while (*s)
  198.       putchar(*s++);                /* send the chars */
  199.    }
  200.  
  201. /*
  202.  * devsnap() - batch mode snapshot; no action needed here.
  203.  */
  204. novalue devsnap()
  205.    {
  206.    }
  207.  
  208. /*
  209.  * devflush() - flush output.
  210.  */
  211. novalue devflush()
  212.    {
  213.    if (stdout->_cnt & 1)        /* ugh! */
  214.       putchar(0);            /* make byte count even */
  215.    fflush(stdout);
  216.    }
  217.  
  218. /*
  219.  * devterm() - terminate graphics
  220.  */
  221. novalue devterm()
  222.    {
  223.    rtcmd(SPCHAR, 0, 1, *SGPX);        /* reset "enter graphics" character */
  224.    rtcmd(QUIT);                /* exit graphics mode */
  225.    putchar(0);                /* dma driver requires "some" nulls */
  226.    putchar(0);
  227.    putchar(0);
  228.    putchar(0);
  229.    putchar(0);
  230.    putchar(0);
  231.    devflush();                /* flush output */
  232.    }
  233.  
  234. /*
  235.  * rtcmd(s, args) - output command to raster tech.
  236.  *  s is a string specifying the command format.  The first character is a
  237.  *  raster tech function code.  Each additional character specifies the format
  238.  *  for outputting one more argument (see below).
  239.  */
  240.  
  241. /*VARARGS1*/
  242. static novalue rtcmd(s, va_alist)
  243. char *s;
  244. va_dcl
  245.    {
  246.    va_list ap;
  247.    char c;
  248.    unsigned int n;
  249.  
  250.    va_start(ap);            /* set up varargs stuff */
  251.    putchar(*s++);            /* output function byte */
  252.    while (c = *s++)
  253.       switch (c) {            /* format characters are: */
  254.          case 'b':            /* b - output byte */
  255.             n = va_arg(ap, unsigned int);
  256.             putchar(n);
  257.             break;
  258.          case 'w':            /* w - output word */
  259.          case 'x':            /* x - output x-coordinate */
  260.          case 'y':            /* y - output y-coordinate */
  261.             n = va_arg(ap, unsigned int);
  262.             putchar(n >> 8);
  263.             putchar(n);
  264.             break;
  265.       }
  266.    }
  267.